package com.buer.storage.service.impl;

import com.buer.storage.dao.CarCategoryDao;
import com.buer.storage.dto.CarCategoryDto;
import com.buer.storage.dto.PutStorageAllDto;
import com.buer.storage.dto.WorderdetailsDto;
import com.buer.storage.entity.CarCategory;
import com.buer.storage.entity.CarCategorytwo;
import com.buer.storage.service.CarCategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CarCategoryServiceImpl implements CarCategoryService {
    @Resource
    private CarCategoryDao carCategoryDao;

    @Override
    public int insertCarCategory(CarCategory carCategory) {
        return carCategoryDao.insertCarCategory(carCategory);
    }

    @Override
    public int deleteCarCategoryById(Integer categoryId) {
       return carCategoryDao.deleteCarCategoryById(categoryId);
    }

    @Override
    public int updateCarCategoryById(CarCategory carCategory) {
        return carCategoryDao.updateCarCategoryById(carCategory);
    }

    @Override
    public List<CarCategory> selectCarCategoryAll() {
        List<CarCategory> categoryList = carCategoryDao.selectCarCategoryAll();
        return categoryList;
    }

    @Override
    public List<CarCategoryDto> findCarCategoryAll (){
        List<CarCategoryDto> all = carCategoryDao.selectCarCategoryById();
        if (all.size() > 0) {
            for (int i = 0; i < all.size(); i++) {
                CarCategorytwo[] categorytwos = carCategoryDao.selectCarCategorytwoById(all.get(i).getCategoryId());
                if (categorytwos.length > 0) {
                    all.get(i).setCarCategorytwos(categorytwos);
                }
            }
        }
        return all;
    }

    @Override
    public List<CarCategorytwo> selectCategorytwoById(Integer categoryId) {
        List<CarCategorytwo> categorytwos = carCategoryDao.selectCategorytwoById(categoryId);
        return categorytwos;
    }
}
